<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>供应商管理</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/material/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/icon.css">
    <script type="text/javascript" src="/static/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        $(function () {
            $('#supplier_dg').datagrid({
                url: '/supplier/selectAll.do',
                fitColumns: true,
                fit: true,
                pagination: true,
                singleSelect: true,
                toolbar: "#supplier_tb",
                rownumbers: true,
                columns: [[
                    {field: 'name', title: '供应商名称', width: 100},
                    {field: 'linkman', title: '联系人', width: 100},
                    {field: 'tel', title: '电话', width: 100},
                    {field: 'currentdate', title: '添加时间', width: 100},
                    {field: 'remark', title: '备注', width: 100}
                ]],
            });

            $("#supplier-dialog").dialog({
                width:250,
                height:320,
                closed:true,
                onClose:function () {
                    //清空表单数据
                    $("#supplier-form").form("clear");
                }
            });
        })
        
        function reloadDepot() {
            $("#supplier_dg").datagrid("reload");
        }

        function addDepot() {
            $("#supplier-dialog").dialog("setTitle","供应商新增");
            $("#supplier-dialog").dialog("open");
        }

        function editDepot() {
            var currentRow = $("#supplier_dg").datagrid("getSelected");
            if (!currentRow) {
                $.messager.alert("温馨提示","亲，请选择一条需要操作的数据","info");
                return;
            }
            $("#supplier-dialog").dialog("setTitle","供应商编辑");
            $("#supplier-dialog").dialog("open");
            //数据回显
            $("#supplier-form").form("load",currentRow);
        }
        
        function save() {
            $("#supplier-form").form("submit",{
                url:"/supplier/saveOrUpdate.do",
                success:function (data) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert("温馨提示","保存成功","info",function () {
                            $("#supplier-dialog").dialog("close");
                            $("#supplier_dg").datagrid("reload");
                        })
                    }else {
                        $.messager.alert("温馨提示","保存失败","error");
                    }
                }
            })
        }
        
        function cancel () {
            $("#supplier-dialog").dialog("close");
        }
    </script>
</head>
<body>
<table id="supplier_dg"></table>
<div id="supplier_tb">
    <a class="easyui-linkbutton" onclick="addDepot()" data-options="iconCls:'icon-add',text:'新增'"></a>
    <a class="easyui-linkbutton" onclick="editDepot()" data-options="iconCls:'icon-edit',text:'编辑'"></a>
    <a id="btn_change" class="easyui-linkbutton" onclick="changeDepot()" data-options="iconCls:'icon-ok',text:'正常'"></a>
    <a class="easyui-linkbutton" onclick="reloadDepot()" data-options="iconCls:'icon-reload',text:'刷新'"></a>
</div>
<div id="supplier-dialog">
    <form id="supplier-form" method="post">
        <input type="hidden" name="id" id="supplier_id">
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="name" style="width: 100%" data-options="label:'名称',labelWidth:60">
        </div>
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="linkman" style="width: 100%" data-options="label:'联系人',labelWidth:60">
        </div>
        <div id="passwordDiv" style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="tel" style="width: 100%" data-options="label:'电话',labelWidth:60">
        </div>
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="remark" style="width: 100%" data-options="label:'备注',labelWidth:60,">
        </div>
        <a class="easyui-linkbutton" onClick="save()" data-options="iconCls:'icon-save',plain:true">保存</a>
        <a class="easyui-linkbutton" onclick="cancel()" data-options="iconCls:'icon-cancel',plain:true">取消</a>
    </form>
</div>
</body>
</html>
